<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
    String path=request.getContextPath();
    String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <base href="<%=basePath%>">
    <title>发票查询配置</title>

    <%@ include file="/WEB-INF/jsp/common/common.jsp" %>
    <script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
    <style type="text/css">
        #detail
        {
            position:relative;
            font-size: 12px;
            background: #fff;
            border: 1px solid #000;
            z-index: 2;
            display: none;
        }
        #detail2
        {
            position:relative;
            font-size: 12px;
            background: #fff;
            border: 1px solid #000;
            z-index: 2;
            display: none;
        }
    </style>
</head>

<script type="text/javascript">
    //根据保单号查询发票
    function queryEinvoice() {
        $('#rePushAllTr').hide();
        var polNo = $('#polNo').val();
        if (polNo == ''){
            $.message("error","发票号不能为空");
            return;
        }
        $.openLoading();
        var polNoList = [polNo];
        $.ajax({
            url: "pushInfoManagerController/queryEinvoiceByPolList",
            type: 'post',
            async: true,
            data: {"polNoList":polNoList},
            success: function (result) {
                $.closeLoading();
                if (result.result == 'error'){
                    $.message("error","查询错误")
                    return;
                }
                var EinvoiceList = $('#EinvoiceList')
                EinvoiceList.html("");
                // var firstbutton = "<input class='input_fxk' name='checkData' id='firstbutton' type='checkBox' value='#'>";
                var tableContent = creatTable("firstButton,polNo,kjzt,lastButton",result);
                EinvoiceList.append(tableContent);

            }
        })
    }
    //查询详情弹窗
    function einvoiceInfo(obj){
        var infoTr = $(obj).parent('td').parent('tr')[0];
        var polNo = infoTr.childNodes[1].innerHTML;
        var polNoList = [polNo];
        $.ajax({
            url: "pushInfoManagerController/queryEinvoiceByPolList",
            type: 'post',
            async: true,
            data: {"polNoList":polNoList},
            success: function (result) {
                $.closeLoading();
                var Einvoice = result.data[0];
                $('#polno').val(Einvoice.polNo);
                $('#fpdm').val(Einvoice.fpdm);
                $('#fphm').val(Einvoice.fphm);
                // $('#url').attr('href','Einvoice.url');
                $('#url').attr('href',Einvoice.url);
                $('#url').text(Einvoice.url)
                $('#addtempletDiv').OpenDiv();
            }
        })
    }
    //重新开票
    function rePushByPol(obj){
        $.openLoading();
        var infoTr = $(obj).parent('td').parent('tr')[0];
        var polNo = infoTr.childNodes[1].innerHTML;
        $.ajax({
            url: 'pushInfoManagerController/rePushByPol',
            type: 'post',
            async: true,
            data: {"polNo":polNo},
            success: function (result) {
                $.message(result.result, result.message)
                if ($('#fileToUpload').val() != '' && $('#EinvoiceList').children().length > 1){
                    //通过模板查询的
                    queryEinvoiceList();
                    $.closeLoading();
                }else {
                    var polNoList = [polNo];
                    //重开之后需要再次查询展示
                    $.ajax({
                        url: "pushInfoManagerController/queryEinvoiceByPolList",
                        type: 'post',
                        async: true,
                        data: {"polNoList":polNoList},
                        success: function (result) {
                            var EinvoiceList = $('#EinvoiceList')
                            EinvoiceList.html("");
                            var tableContent = creatTable("firstButton,polNo,kjzt,lastButton",result);
                            EinvoiceList.append(tableContent);
                            $.closeLoading();
                        }
                    })
                }
            }
        })
    }
    //全部重开
    function rePushAllByPolList() {
        var polNoList='';
        $("input[name='checkData']:checked").each(function(){
            if(''==polNoList){
                polNoList = $(this).parent().parent().children("td:eq(1)").html()
            }else{
                polNoList =polNoList+","+ $(this).parent().parent().children("td:eq(1)").html()
            }
        });
        if(polNoList==''){
            $.message("error", "请至少选择一条");
            return;
        }
        $.ajax({
            url: 'pushInfoManagerController/rePushByPolList',
            type: 'post',
            async: true,
            data: {"polNoList":polNoList},
            success: function (result) {
                //重开成功后再次查询刷新
                queryEinvoiceList();
            }
        })
    }

    //上传excel事件
    function queryEinvoiceList(){
        $.openLoading();
        var fileNameStr = $('#fileToUpload').val();
        fileNameStr = fileNameStr+"";
        var lastDotIndex = fileNameStr.lastIndexOf(".");
        if(lastDotIndex==-1){
            $.closeLoading();
            $.message("error","请选择扩展名为 .xls 的文件上传");
            return;
        }else{
            var extName = fileNameStr.substring(lastDotIndex+1, fileNameStr.length);
            if(extName.toLowerCase() != "xls"){
                $.closeLoading();
                $.message("error","请选择扩展名为 .xls 的文件上传");
                return;
            }
        }
        $.ajaxFileUpload({
            url:'<%=path%>/pushInfoManagerController/xlsPolNoListFileUpload',
            fileElementId :'fileToUpload',//file控件id
            dataType: 'json',
            success : function (result){
                if (result.result == 'error'){
                    $.closeLoading();
                    $.dialog({
                        width: 358,
                        top:40,
                        modal:true,
                        Close:true,
                        cancel:null,
                        content: result.message
                    });
                    return;
                }
                var polNoList = result.data;
                $.ajax({
                    url: "pushInfoManagerController/queryEinvoiceByPolList",
                    type: 'post',
                    async: true,
                    data: {"polNoList":polNoList},
                    success: function (result) {
                        var EinvoiceList = $('#EinvoiceList')
                        EinvoiceList.html("");
                        // var firstbutton = "<input class='input_fxk' name='checkData' id='firstbutton' type='checkBox' value='#'>";
                        var tableContent = creatTable("firstButton,polNo,kjzt,lastButton",result);
                        EinvoiceList.append(tableContent);
                        $.closeLoading();
                        //将全部重开按钮显示
                        $('#rePushAllTr').show();
                    }
                })
            }
        })
    }

    function loadEinvoice(resultData) {
        var tableObj = $('#EinvioceTable')
        for (var i = 0; i < resultData.data.length; i++) {
            var td = document.createElement("td")
            tableObj.append()
        }
    }
    //统一 关闭窗口(传入要关闭DIV的id)
    function closeCurrentDIV(obj){
        $("#"+obj).CloseDiv();
    }
</script>
<body>
<div class="current">
    <table class="current_table_1">
        <tbody>
        <tr class="f2">
            <td><img src="./images/current_1.jpg"></td>
            <td class="current_table_1_td">
                <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                <span style=" color:#136bab; ">推送信息管理
                     <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>发票查询
                 </span>
            </td>
            <td><img src="./images/current_3.jpg"></td>
        </tr>
        </tbody>
    </table>
</div>
<table class="table_02">
    <tr>
        <td>
            <table class="search_table" id="queryNlifePlanCriteriaTable">
                <tr height="30px">
                    <td style="border: 0;text-align: right;" nowrap="nowrap">保单号：</td>
                    <td style="border: 0;text-align: left;padding-right: 70px">
                        <input name="polNo" id="polNo" class="input_text" style="width:200px;" size="25"/>
                        <input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryEinvoice()"/>
                        <span id="resultInfo" style="display:none;color:red"></span>
                    </td>
                    <td nowrap="nowrap"><a href="<%=path%>/pushInfoManagerController/downloadPolnoTemplet?&templateType=PolNoList" >&nbsp;&nbsp;模板下载&nbsp;</a></td>
                    <td nowrap="nowrap"><input  id="fileToUpload" type='file' name="fileToUpload" multiple="multiple" size='10'/><input type="button" value="批量查询" class="input_button_2" onclick="queryEinvoiceList()"/></td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td>
            <table id="EinvioceTable"  class="content_table_1">
                <thead>
                    <tr class="f1">
                        <th style="width:3%">选择</th>
                        <th style="width:9%">保单号</th>
                        <th style="width:6%">状态</th>
                        <th style="width:5%">操作</th>
                    </tr>
                </thead>
                <tbody id="EinvoiceList">
                </tbody>
            </table>
        </td>
    </tr>
    <tr style="display: none" id="rePushAllTr">
        <td style="text-align: left">
            <input type="button" id="rePushAllBtn" class="input_button_2" value="选中重开" onclick="rePushAllByPolList()">
        </td>
    </tr>

</table>
<div id="addtempletDiv"  style="display:none;width:60%">
    <input type="hidden" id="row_num" name="row_num" value="0"/>
    <div class="table_title_div">
        <table class="table_title" style='width:100%;'>
            <tr>
                <td width="10%"></td>
                <td width="80%" id="interfaceName"></td>
                <td width="10%" align="right"><img src="<%=path%>/images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('addtempletDiv')"/></td>
            </tr>
        </table>
    </div>
    <form id="inputForm" action="save.jhtml" method="post" enctype="multipart/form-data">
        <table class="table_02" id="addtempletTable" align="center" >
            <tbody>
            <tr>
                <td>
                    <table id="productTempletTable"  class="content_table_1">
                        <tbody>
                        <tr>
                            <td width="40%" style="text-align:right;border-right:0px;">发票代码：&nbsp;&nbsp;</td>
                            <td width="60%" style="text-align:left"><input type="text" style="width: 250px" class="input_text" id="fpdm" disabled="true"></td>
                        </tr>
                        <tr>
                            <td width="40%" style="text-align:right;border-right:0px;">发票号：&nbsp;&nbsp;</td>
                            <td width="60%" style="text-align:left"><input type="text" style="width: 250px" class="input_text" id="fphm" disabled="true"></td>
                        </tr>
                        <tr>
                            <td width="40%" style="text-align:right;border-right:0px;">下载链接：&nbsp;&nbsp;</td>
                            <td width="60%" style="text-align:left"><a style="width: 250px" id="url" disabled="true">点击下载</a></td>
                        </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            </tbody>
        </table>
        <div align="center">
            <input class="input_button_3" name="" type="button" onclick="closeCurrentDIV('addtempletDiv')" value="取消">
        </div>
    </form>
</div>
</body>
</html>